//
//  ViewController.m
//  4-26z
//
//  Created by 钟纪旺 on 16/4/26.
//  Copyright © 2016年 zjw. All rights reserved.
//

#import "ViewController.h"
#import "nb.h"
@interface ViewController ()<UITableViewDataSource>
{
    NSArray * data;


}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    tableView.dataSource = self;
    [self.view addSubview:tableView];
    
    NSBundle *bundle = [NSBundle mainBundle];
    NSURL * url =[bundle URLForResource:@"abc" withExtension:@""];
    NSString *text = [[NSString alloc]initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
    NSLog(@"hi %@",text);
    
    NSArray *arr= [text componentsSeparatedByString:@"\n"];
    NSMutableArray *tmp = [NSMutableArray new];
    for (int i=0; i<arr.count; i++) {
        NSString *item = arr[i];
        NSArray *p = [item componentsSeparatedByString:@","];
        nb *per = [nb new];
        per.one = p[0];
        per.two = p[1];
        [tmp addObject:per];
    }
    data = tmp;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return data.count;

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    nb *p = data[indexPath.row];
    cell.textLabel.text = p.one;
    cell.detailTextLabel.text = p.two;
    return cell;

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
